#!/bin/bash


tsrc=$(adapt tool get http://trilinos.sandia.gov/download/files/trilinos-11.4.3-Source.tar.bz2)

bld_dir=/tmp/adapt/lifev-package

mkdir -p $bld_dir/{lifev,trilinos}
pushd $bld_dir/lifev # on local disk everything is lighting fast.. (in comp. to nfs)

#1. get sources

# first the lifev package
yes n | cp -i ~/adapt/repo/lib/lifev/lifev-2.2.1.tar.bz2 .
tar kxjf lifev-2.2.1.tar.bz2 2>/dev/null #keep files if they exist (do not overwrite)
mkdir -p lifev-2.2.1-bld

# now the trilinos
cd ../trilinos
wget -nc http://trilinos.sandia.gov/download/files/trilinos-11.4.3-Source.tar.bz2
tar kxjf trilinos-11.4.3-Source.tar.bz2 2>/dev/null
rm -rf trilinos-11.4.3-Bld/* 2>&-
mkdir -p trilinos-11.4.3-Bld 2>&-

# first build trilinos
cd trilinos-11.4.3-Bld

#warning: is it -D ParMETIS_LIBRARY_NAMES:STRING=parmetis correct?
adapt cmake \
  -D CMAKE_BUILD_TYPE:STRING=RELEASE \
  -D CMAKE_INSTALL_PREFIX:STRING=/home/jaross/adapt/soft \
  -D TPL_ENABLE_MPI:BOOL=ON \
  -D TPL_ENABLE_BLAS:BOOL=ON \
  -D TPL_ENABLE_LAPACK:BOOL=ON \
  -D TPL_ENABLE_HDF5:BOOL=ON \
  -D TPL_ENABLE_ParMETIS:BOOL=ON \
  -D ParMETIS_LIBRARY_NAMES:STRING=parmetis \
  -D TPL_ENABLE_UMFPACK:BOOL=ON \
  -D TPL_ENABLE_AMD:BOOL=ON \
  -D TPL_ENABLE_Boost:BOOL=ON \
  -D TPL_ENABLE_Zlib:BOOL=ON \
  -D TPL_ENABLE_Pthread:BOOL=ON \
  -D Trilinos_ENABLE_Teuchos:BOOL=ON \
  -D Trilinos_ENABLE_Epetra:BOOL=ON \
  -D Trilinos_ENABLE_EpetraExt:BOOL=ON \
  -D Trilinos_ENABLE_Zoltan:BOOL=ON \
  -D Trilinos_ENABLE_AztecOO:BOOL=ON \
  -D Trilinos_ENABLE_Belos:BOOL=ON \
  -D Trilinos_ENABLE_Anasazi:BOOL=ON \
  -D Trilinos_ENABLE_Amesos:BOOL=ON \
  -D Trilinos_ENABLE_Ifpack:BOOL=ON \
  -D Trilinos_ENABLE_ML:BOOL=ON \
  -D Trilinos_ENABLE_NOX:BOOL=ON \
  -D Trilinos_ENABLE_Rythmos:BOOL=ON \
  -D Trilinos_ENABLE_Thyra:BOOL=ON \
  ../trilinos-11.4.3-Source

make

make install

ret=$?

popd
exit $ret

# everything here would be in adapt, but I do not want to complicate now
./configure --prefix=/home/jaross/adapt/soft
make
make install
adapt env prepend PATH ~/adapt/soft/bin
adapt env prepend LD_LIBRARY_PATH ~/adapt/soft/lib

popd
